// 判断数据类型
export function myTypeof(val){
  let type = typeof(val);
  let toStr = Object.prototype.toString;
  let res = {
    '[object Array]':'array',
    '[object Object]':'object',
    '[object Number]':'object number',
    '[object String]':'object string',
    '[object Boolean]':'object boolean',
  };
  if(val === null){
    return 'null';
  }else if(type === 'object'){
    let ret = toStr.call(val);
    return res[ret];
  }else{
    return type;
  }
}
// 连接引用对象（Array Object）
export function myConnect(){
  let conData = null;
  let dataType = this.$myTypeof(arguments[0]);
  if(![ 'array','object' ].includes(dataType)) return;
  if(dataType === 'array'){
    conData = [];
    for(let item of arguments) conData = conData.concat(item);
  } else {
    conData = {};
    for(let item of arguments) conData = Object.assign(conData,item);
  }
  return conData;
}

// 数组去重
export function noRepetitionArr(arr){
  return Array.from(new Set(arr));
}

// 时间格式化函数：
export function handleTime(time, format) {
  if (time == null || time == undefined || time == '') {
    return '';
  }
  var t = new Date(time);
  var tf = function(i) {
    return (i < 10 ? '0' : '') + i;
  };
  return format.replace(/yyyy|MM|dd|HH|mm|ss/g, function(a) {
    switch (a) {
    case 'yyyy':
      return tf(t.getFullYear());
    case 'MM':
      return tf(t.getMonth() + 1);
    case 'mm':
      return tf(t.getMinutes());
    case 'dd':
      return tf(t.getDate());
    case 'HH':
      return tf(t.getHours());
    case 'ss':
      return tf(t.getSeconds());
    }
  });
}
